import { baseUrl } from "./config.js"

//首页头部榜单
export function topList() {
	let listIDs = ['3', '0', '2', '1']
	return new Promise((resolve, reject) => {
		uni.request({
			url:`${baseUrl}/toplist/detail`,
			method: "GET",
			data:{},
			success:res => {
				// 截取数据的前四条
				let resule = res.data.list;
				resule.length = 4;
				for(var i = 0; i < listIDs.length; i++) {
					resule[i].listIDs = listIDs[i]
				}
				resolve(resule);
			}
		})
	})
}

//首页详情
export function list(listIDs) {
	return uni.request({
		url:`${baseUrl}/playlist/detail?id=${listIDs}`,
		method: "GET",
	});
}

//获取歌曲详情
export function songDetail(songId) {
	return uni.request({
		url:`${baseUrl}/song/detail?ids=${songId}`,
		method: "GET",
	});
}

//获取相似音乐
export function simiSong(songId) {
	return uni.request({
		url:`${baseUrl}/simi/song?id=${songId}`,
		method: "GET",
	});
}

//歌曲评论
export function commentMusic(songId) {
	return uni.request({
		url:`${baseUrl}/comment/music?id=${songId}`,
		method: "GET",
	});
}

//获取歌词
export function lyric(songId) {
	return uni.request({
		url:`${baseUrl}/lyric/music?id=${songId}`,
		method: "GET",
	});
}

//Vercel 部署
export function songUrl(songId) {
	return uni.request({
		url:`${baseUrl}/song/url?id=${songId}`,
		method: "GET",
	});
}

//热搜列表(详细)http://localhost:3000/search/hot/detail
export function searchHot(songId) {
	return uni.request({
		url:`${baseUrl}/search/hot/detail`,
		method: "GET",
	});
}

//搜索 http://localhost:3000/search?keywords=少年
export function searchWords(word) {
	return uni.request({
		url:`${baseUrl}/search?keywords=${word}`,
		method: "GET",
	});
}

//搜索建议
// http://localhost:3000/search/suggest?keywords=少年&type=mobile
export function searchSuggest(word) {
	return uni.request({
		url:`${baseUrl}/search/suggest?keywords=${word}&type=mobile`,
		method: "GET",
	});
}